/**
 * @author 雷明浩
 * @date 2025/7/3 9:40
 */
public class MinNumberDisappeared {
    // 缺失的第一个正整数
    // https://www.nowcoder.com/practice/50ec6a5b0e4e45348544348278cdcee5?tpId=295&tqId=2188893&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3DSQL%25E7%25AF%2587%26topicId%3D295
    public int minNumberDisappeared (int[] nums) {
        // write code here
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            if (nums[i] <= 0 || nums[i] > len) {
                nums[i] = len + 1;
            }
        }
        for (int i = 0; i < len; i++) {
            int tmp = Math.abs(nums[i]);
            if (tmp <= len) {
                nums[tmp-1] = -Math.abs(nums[tmp-1]);
            }
        }
        for (int i = 0; i < len; i++) {
            if (nums[i] > 0) {
                return i + 1;
            }
        }
        return len + 1;
    }
}